﻿using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class TargetHead
{
    GameObject _root;
    Text _textName;
    Button _btn;
    Slider _hp;
    public TargetHead()
    {
        _root=UIMgr.GetInstance().Add("UI/FightUI/TargetHead", UILayer.FightUI);
      
        _textName = _root.Find<Text>("Name");
        //_btn = _root.Find<Button>("Name");
        //_btn.onClick.AddListener(OnBtnClick);
        _hp = _root.Find<Slider>("SliderHP");
    }

    private void OnBtnClick()
    {
        Debug.Log("查看属性");
    }


    //显示或者隐藏头像
    public void SetActive(bool bActive)
    {
        _root.SetActive(bActive);
    }

    public void SetTargetInfo(string curName, float curHp, float maxHp,bool bActive = true)
    {
        _textName.text = curName;
        _hp.value = curHp / maxHp;
        SetActive(bActive);
    }

    public void Hide()
    {
        _root.SetActive(false);
    }
    public void Show()
    {
        _root.SetActive(true);
    }
}